<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c" %>   
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Amaze UI Admin index Examples</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="bgo_lib/amazeui/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="bgo_lib/amazeui/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <!-- cssjs -->
    <jsp:include page="/WEB-INF/page/bgo_layout/cssjs.jsp" />
    <script src="js/date.pattern.js"></script>
</head>

<body data-type="widgets">
    <script src="bgo_lib/amazeui/assets/js/theme.js"></script>
    <div class="am-g tpl-g">
  <!-- 头部 -->
        <jsp:include page="/WEB-INF/page/bgo_layout/head.jsp" />
        <!-- 侧边导航栏 -->
         <jsp:include page="/WEB-INF/page/bgo_layout/left.jsp" />
        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">


                <div class="row">

                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">house管理</div>
                                <div class="widget-function am-fr">
                                    <a href="javascript:;" class="am-icon-cog"></a>
                                </div>
                            </div>  
                            <div class="widget-body am-fr">

                                <form action="houseAction_saveOrUpdateOpt_house.hp" method="post"   class="am-form tpl-form-line-form">
                                    <c:if test="${house.date!=null}">
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">编号 ：</label>
                                        <div class="am-u-sm-9">
                                            <input value="${house.id}" readonly="readonly" name="id" type="text" class="tpl-form-input" id="user-name" placeholder="请输入编号">
                                        </div>
                                    </div>
                                    </c:if>
                                     <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">封面图：</label>
                                        <div class="am-u-sm-9">
                                        <c:if test="${house.date==null}">
                                        <img style="width: 121px;height: 121px" id="img_url" src="img/headimg.jpg" /> <button type="button"  id="kdUploadSelect"  class="am-btn am-btn-default am-btn-success">上传封面</button>
                                        </c:if> 
                                        <c:if test="${house.date!=null}">
                                          <c:if test="${house.img_url=='' || house.img_url==null}">
                                            <img style="width: 121px;height: 121px" id="img_url" src="img/headimg.jpg" /> <button type="button"  id="kdUploadSelect"  class="am-btn am-btn-default am-btn-success">上传封面</button>
                                          </c:if>
                                          
                                          <c:if test="${house.img_url!=null &&  house.img_url!=''}">
                                            <img style="width: 121px;height: 121px" id="img_url" src="${house.img_url}" /> <button type="button"  id="kdUploadSelect"  class="am-btn am-btn-default am-btn-success">上传封面</button>
                                          </c:if>                                      
                                        </c:if>  
                                        <c:if test="${house.id==null }">
                                        <input value="${uuid}" name="id" type="hidden"   />    
                                        </c:if>
                                        <input value="${userinfo.id}" name="user.id" type="hidden"   /> 
                                        <input value="${house.date}" name="date" type="hidden"  id="hidden_date" />    
                                        <input value="${house.img_url}" name="img_url" type="hidden" id="hidden_img_url" /> 
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">标题 ： </label>
                                        <div class="am-u-sm-9">
                                            <input value="${house.title}" name="title"  type="text" class="tpl-form-input" id="user-name" placeholder="请输入名称">
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">价格 ： </label>
                                        <div class="am-u-sm-9">
                                            <input value="${house.price}" name="price"  type="text" class="tpl-form-input" id="user-name" placeholder="价格">
                                        </div>
                                    </div>
                                     <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">出租方式：</label>
                                       
                                        <select name="conditions" data-am-selected="{searchBox: 1}">
                                         <option value="整租">整租</option>
                                         <option value="合租">合租</option>
										</select>
                                    </div>
                                     <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">时间方式：</label>
                                       
                                        <select name="price_unit" data-am-selected="{searchBox: 1}">
                                         <option value="晚">晚</option>
                                         <option value="月">月</option>
                                         <option value="年">年</option>
										</select>
                                    </div>
                                     <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">城市 ：</label>
                                        <select name="city.id" data-am-selected="{searchBox: 1}">
                                         <option value="0">请选择</option>
                                         <c:forEach items="${cityList}" var="item">
                                         <c:if test="${house.city.id==item.id}" var="isSelect">
                                          <option selected="selected" value="${item.id}">${item.name}</option>
                                         </c:if>
										 <c:if test="${!isSelect}">
                                          <option  value="${item.id}">${item.name}</option>
                                         </c:if>		 
										 </c:forEach>	
										</select>
                                    </div>
                                     <div class="am-form-group">
                                     <label for="user-name" class="am-u-sm-3 am-form-label">街道 ：</label>
                                        <select name="street.id" data-am-selected="{searchBox: 1}">
                                         <option value="0">请选择</option>
                                         <c:forEach items="${streetList}" var="item">
                                         <c:if test="${house.city.id==item.id}" var="isSelect">
                                          <option selected="selected" value="${item.id}">${item.name}</option>
                                         </c:if>
										 <c:if test="${!isSelect}">
                                          <option  value="${item.id}">${item.name}</option>
                                         </c:if>		 
										 </c:forEach>	
										</select>
										</div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">户型： </label>
                                        <div class="am-u-sm-9">
                                            <input value="${house.house_type}" name="house_type"  type="text" class="tpl-form-input" id="user-name"  >
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">简介说明 ：</label>
                                        <div class="am-u-sm-9">
                                            <textarea name="mark" class="" rows="5" id="user-intro" placeholder="请输入备注">${house.mark}</textarea>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">交通说明 ：</label>
                                        <div class="am-u-sm-9">
                                            <textarea name="traffic" class="" rows="5" id="user-intro"  >${house.traffic}</textarea>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">配套设施 ：</label>
                                        <div class="am-u-sm-9">
                                            <textarea name="mating" class="" rows="5" id="user-intro" >${house.mating}</textarea>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">上传图片 ：</label>
                                     <div class="am-u-sm-9">
                                    <div id="kdViewDiv"  class="hp-upload-div" ></div>    
                                    </div>
                                    </div>
                                    <div class="am-form-group">
                                    
                                      <label for="user-name" class="am-u-sm-3 am-form-label">上传成功图片 ：</label>
                                     <div class="am-u-sm-9">
                                     <div  class="hp-upload-div">
                                    <ul id="upload_img" data-am-widget="gallery" class="am-gallery am-avg-sm-2  am-avg-md-3 am-avg-lg-4 am-gallery-default" data-am-gallery="{ pureview: true }" >
								      </ul>
								      </div>
								      </div>
								      </div>
                                    <div class="am-form-group">
                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                            <input type="submit" class="am-btn am-btn-primary tpl-btn-bg-color-success " value="提交" />
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
  <jsp:include page="/WEB-INF/page/bgo_layout/foot.jsp" />
	<script type="text/javascript">
		var webPath='${webPath}';
		var imgPath='${imgPath}';
		var user_id = "";
		if(${house.date==null}){
			user_id = "${uuid}";
		}else{
			user_id = "${house.id}"
		}
		 $(function() { 
			//  按钮绑定
			$.hpUpload("uploadAction_uploadFileDisk.hp", {
				"path" : "/image"
			}, function(json) {
				console.log(json);
				$("#img_url").attr('src', imgPath + json.imgPath);
				$("#hidden_img_url").attr('value', imgPath + json.imgPath);
			});
			if(${house.date!=null}){
				 $.ajax({
						url: "imgArrAction_queryByHouseId.hp",
						data: {"house.id" : user_id},
						type: "post",
						dataType: "json",
						success: function(json) {
							var upload_img="";//已上传img
							$("#upload_img").html('');
							$.each(json.viewList,function(index,item){
								var upload_img_div='<li><div class="am-gallery-item">'+
								'<div   class="kdfile kdpvImg" style="float:left;width:110px;height:110px"><img style="width:110px;height:110px" class="hp-upload-div-removeUploadBtnDiv-img" src="${imgPath }'+item.img_url+'"><div class="hp-upload-div-removeUploadBtnDiv-btn" style="height: 0px;"><span class="remove" onclick="delete_img('+item.id+')">删除</span></div></div>'+
								'</div></li>';
								upload_img+=upload_img_div;
							})
							$("#upload_img").append(upload_img);
						},
						error: function() {
							alert("服务器有误2,请联系管理员")
						}
					}); 
			};
		}); 
		$.hpUpload_plus.viewUpload("uploadAction_uploadFiles.hp",{"path" : "/image","id":user_id},function(json){
			var upload_img_add = "";
			$.each(json.imgPath,function(index,item){
				console.log(item);
				var upload_img_div='<li><div class="am-gallery-item">'+
				'<div   class="kdfile kdpvImg" style="float:left;width:110px;height:110px"><img style="width:110px;height:110px" class="hp-upload-div-removeUploadBtnDiv-img" src="${imgPath }'+item.img_url+'"><div class="hp-upload-div-removeUploadBtnDiv-btn" style="height: 0px;"><span class="remove" onclick="delete_img('+item.id+')">删除</span></div></div>'+
				'</div></li>';
				upload_img_add += upload_img_div;
			});
			$("#upload_img").html("");
			$("#upload_img").append(upload_img_add);
		});
		function delete_img(id) {
			 $.ajax({
					url: "imgArrAction_ajaxDelete.hp",
					data: {"id" : id},
					type: "post",
					dataType: "json",
					success: function(json) {
						layer.msg('删除成功');
					},
				}); 
		};
	</script>
	
</body>

</html>